//
//  FarmFoodListCell.m
//  YK_BaseMediator
//
//  Created by edward on 2021/3/12.
//  Copyright © 2021 Edward. All rights reserved.
//

#import "FarmFoodListCell.h"
#import "YKFarmViewModel.h"
#import <Masonry/Masonry.h>

@interface FarmFoodListCell ()
///
@property(nonatomic,strong) UILabel *titleLabel;
///
@property(nonatomic,strong) UILabel *foodnameLabel;
///
@property(nonatomic,strong) UILabel *muchLabel;
///
@property(nonatomic,strong) UILabel *eattimeLabel;
///
@property(nonatomic,strong) UILabel *createTimeLabel;
///
@property(nonatomic,strong) UILabel *drugNameLabel;
///
@property(nonatomic,strong) UILabel *drugMuchLabel;
@end

@implementation FarmFoodListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.foodnameLabel];
    [self.contentView addSubview:self.muchLabel];
    [self.contentView addSubview:self.eattimeLabel];
    [self.contentView addSubview:self.createTimeLabel];
    [self.contentView addSubview:self.drugNameLabel];
    [self.contentView addSubview:self.drugMuchLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
    }];
    
    [self.foodnameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5);
        make.left.mas_equalTo(self.titleLabel.mas_left);
        make.width.mas_equalTo(self.titleLabel.mas_width).multipliedBy(0.5);
    }];
    
    [self.muchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.mas_equalTo(self.foodnameLabel);
        make.right.mas_equalTo(self.titleLabel.mas_right);
    }];
    
    [self.eattimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.mas_equalTo(self.foodnameLabel);
        make.top.mas_equalTo(self.foodnameLabel.mas_bottom).offset(5);
    }];
    [self.drugNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.mas_equalTo(self.eattimeLabel);
        make.top.mas_equalTo(self.eattimeLabel.mas_bottom).offset(5);
    }];
    [self.drugMuchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.drugNameLabel.mas_right);
        make.width.mas_equalTo(self.drugNameLabel);
        make.right.mas_equalTo(self.titleLabel.mas_right);
        make.top.mas_equalTo(self.drugNameLabel.mas_top);
    }];
    [self.createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.drugNameLabel.mas_bottom).offset(5);
        make.left.mas_equalTo(self.titleLabel.mas_left);
        make.right.mas_equalTo(self.titleLabel.mas_right);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10).priorityHigh();
    }];
}


- (void)configDataWithViewModel:(YKFarmViewModel *)viewModel indexPath:(NSIndexPath *)indexPath dataSource:(NSArray *)dataSource
{
    @weakify(self);
    [viewModel getFoodDetail:indexPath block:^(NSString * _Nonnull MealTime, NSString * _Nonnull foodname, NSString * _Nonnull much, NSString * _Nonnull eattime, NSString * _Nonnull createTime, NSString * _Nonnull drugname, NSString * _Nonnull drugmuch, NSString * _Nonnull foodId) {
        
        @strongify(self);
        self.titleLabel.text = MealTime;
        self.foodnameLabel.text = foodname;
        self.muchLabel.text = much;
        self.eattimeLabel.text = eattime;
        self.createTimeLabel.text = createTime;
        self.drugNameLabel.text = drugname;
        self.drugMuchLabel.text = drugmuch;
    }];
}

- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        _titleLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _titleLabel.textColor = UIColor.labelColor;
        } else {
            
            _titleLabel.textColor = UIColor.blackColor;
        }
        _titleLabel.font = [UIFont systemFontOfSize:22 weight:UIFontWeightRegular];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UILabel *)foodnameLabel
{
    if(!_foodnameLabel)
    {
        _foodnameLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _foodnameLabel.textColor = UIColor.labelColor;
        } else {
            
            _foodnameLabel.textColor = UIColor.blackColor;
        }
        _foodnameLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _foodnameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _foodnameLabel;
}

- (UILabel *)muchLabel
{
    if(!_muchLabel)
    {
        _muchLabel = [[UILabel alloc]init];
        _muchLabel.textColor = UIColor.redColor;
        _muchLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _muchLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _muchLabel;
}

- (UILabel *)eattimeLabel
{
    if(!_eattimeLabel)
    {
        _eattimeLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _eattimeLabel.textColor = UIColor.labelColor;
        } else {
            
            _eattimeLabel.textColor = UIColor.blackColor;
        }
        _eattimeLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _eattimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _eattimeLabel;
}

- (UILabel *)createTimeLabel
{
    if(!_createTimeLabel)
    {
        _createTimeLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _createTimeLabel.textColor = UIColor.labelColor;
        } else {
            
            _createTimeLabel.textColor = UIColor.blackColor;
        }
        _createTimeLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _createTimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _createTimeLabel;
}

- (UILabel *)drugNameLabel
{
    if(!_drugNameLabel)
    {
        _drugNameLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _drugNameLabel.textColor = UIColor.labelColor;
        } else {
            
            _drugNameLabel.textColor = UIColor.blackColor;
        }
        _drugNameLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _drugNameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _drugNameLabel;
}

- (UILabel *)drugMuchLabel
{
    if(!_drugMuchLabel)
    {
        _drugMuchLabel = [[UILabel alloc]init];
        _drugMuchLabel.textColor = UIColor.redColor;
        _drugMuchLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _drugMuchLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _drugMuchLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
